import 'package:flutter/material.dart';

void main() {
  runApp(new LyricsInformationMain());
}

class LyricsInformationMain extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Fade Demo',
      theme: new ThemeData(
        primarySwatch: Colors.green,
      ),
      home: new MyFadeTest(title: 'Fade Demo'),
    );
  }
}

class MyFadeTest extends StatefulWidget {
  MyFadeTest({Key key, this.title}) : super(key: key);
  final String title;

  @override
  State createState() => new _MyFadeTest();
}

var imagesss = Image.asset('images/minIcon/defaultAlbumImage/defaultAlbumImage.png');

class _MyFadeTest extends State<MyFadeTest> with TickerProviderStateMixin {
  AnimationController controller; //动画控制器
  CurvedAnimation curved; //曲线动画，动画插值，

  @override
  void initState() {
    //初始化，当当前widget被插入到树中时调用
    super.initState();
    controller = new AnimationController(vsync: this, duration: const Duration(seconds: 3));
    curved = new CurvedAnimation(parent: controller, curve: Curves.linear); //模仿小球自由落体运动轨迹
    Tween(begin: 0.0, end: 2.0).animate(controller)
      //添加了状态监听
      ..addStatusListener((state) {
        //当动画结束时执行动画反转
        if (state == AnimationStatus.completed) {
          controller.reset();
          controller.forward();
          //当动画在开始处停止再次从头开始执行动画
        } else if (state == AnimationStatus.dismissed) {
          controller.reset();
          controller.forward();
        }
      });
    controller.forward();
//    controller.forward();//放在这里开启动画 ，打开页面就播放动画
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('FadeTest'),
      ),
      body: new Center(
//        child: new FadeTransition(//透明度动画
//          opacity: curved,//将动画传入不同的动画widget
//          child: new FlutterLogo(//创建一个小部件，用于绘制Flutter徽标
//            size: 200.0,
//          ),
//        ),
        child: new RotationTransition(
          //旋转动画
          turns: curved,
          child: imagesss,
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: () {
          setState(
            () {
              imagesss = Image.network('http://y.gtimg.cn/music/photo_new/T002R300x300M000004LJaz22RN4vs.jpg');
            },
          );
          controller.reset();
          controller.forward(); //向前播放动画
        },
        tooltip: 'fade',
        child: new Icon(Icons.track_changes),
      ),
    );
  }
}
